package com.litbw.publicobservable;

import com.litbw.event.Event;

/**
 * The EventDetailMessage is used to send signals and Event objects to any
 * observer which must take action using this Events from the database. Two
 * constructors are provided, one with ONLY a signal (EventDetailSignal), and
 * one which accepts a signal and an Event. This is for the cases such as the
 * clear signal, which won't need to provide an Event object.
 * @author Michael Morris
 *
 */
public class EventDetailMessage extends SimpleMessage {

	/**
	 * ADD EVENT DETAIL SIGNALS HERE AS NECESSARY.
	 * 
	 * The EventDetailSignal enumeration describes signals which may be sent
	 * either alone or along with Event data to observers which much take
	 * action on this data.
	 * 
	 * @author Michael Morris
	 *
	 */
	public static enum EventDetailSignal {
		UPDATE,
		CLEAR
	}
	
	/**
	 * The signal stored with this message.
	 */
	private final EventDetailSignal signal;
	
	/**
	 * The Event data, if any, stored with this message.
	 */
	private final Event event;
	
	/**
	 * Create a new EventDetailMessage supplying a signal and defaulting the
	 * Event data to null.
	 * @param sig The signal to send.
	 */
	public EventDetailMessage(final EventDetailSignal sig) {
		this(sig, null);
	}
	
	/**
	 * Create a new EventDetailMessage supplying both a signal and Event data
	 * (which may be null).
	 * @param sig The signal to send.
	 * @param e The Event data, if any, to send along with the signal.
	 */
	public EventDetailMessage(final EventDetailSignal sig, final Event e) {
		
		if (sig == null)
			throw new IllegalArgumentException("must specify a signal");
		
		signal = sig;
		event = e;
		
	}
	
	/**
	 * Get the signal stored in this message.
	 * @return A EventDetailSignal reference.
	 */
	public final EventDetailSignal getSignal() {
		return signal;
	}
	
	/**
	 * Get the Event data, if any, which is stored in this message.
	 * @return An Event object with data, or null if no Event was sent.
	 */
	public final Event getEvent() {
		return event;
	}
	
}
